package com.zb.wx.controller;

import com.zb.entity.AccounLoginInfo;
import com.zb.exception.WxException;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.WxPublicNoAuthorizeThirdService;
import com.zb.service.ZjCustomerWxAuthorService;
import com.zb.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author WEN
 * @Date 2024/2/28 0028
 **/
@Api(tags = "微信公众号授权第三方平台类接口")
@RestController
@RequestMapping("/wx/publicNo/authorizeThird")
public class WxPublicNoAuthorizeThirdController {
    @Resource
    private WxPublicNoAuthorizeThirdService wxPublicNoAuthorizeThirdService;


    @ApiOperation("获取微信第三方平台授权")
    @GetMapping("/getWxThridAuthorizePage/{uuid}")
    public Result getWxThridAuthorizePage(HttpServletRequest request, @PathVariable @ApiParam(value = "发起微信认证授权时的uuid") String uuid) throws WxException {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        return Result.success("获取第三方平台授权成功").data(PageUtil.row(wxPublicNoAuthorizeThirdService.getAuthorizePage(loginInfo, uuid)));
    }

    @ApiOperation("保存商家取消微信授权")
    @PutMapping("/saveCancelCustomerWxAuthor")
    public Result cancelCustomerWxAuthor(HttpServletRequest request) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        wxPublicNoAuthorizeThirdService.cancelCustomerWxAuthor(custAccId);
        return Result.success("取消微信授权成功");
    }
}
